﻿using System;
using System.Data;
using System.Configuration;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Data.SqlClient;
using System.Collections;
using System.Web.Security;



public partial class main : System.Web.UI.Page
{
    CommonClass ccobj = new CommonClass();
    GoodsClass gcobj = new GoodsClass();
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            refinebind();
            HotBind();
            DiscountBind();
        }
    }


    public string GetVarMKP(string strMarketPrice)
    {
        return ccobj.Varstr(strMarketPrice, 2);
    }


    public string GetVarHot(string strHotPrice)
    {
        return ccobj.VarStr(strHotPrice, 2);
    }


    protected void refinebind()
    {
        gcobj.DLDeplayGI(1, this.dLRefine, "Refine");
    }


    protected void HotBind()
    {
        gcobj.DLDeplayGI(3, this.dlHot, "Hot");
    }


    protected void DiscountBind()
    {
        gcobj.DLDeplayGI(2, this.dlDiscount, "Discount");
    }


    protected void dLRefine_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detailSee")
        {
            AddressBack(e);
        }
        else if (e.CommandName == "buy")
        {
            //addshodcart(e);
            AddShopCart(e);
        }

    }


    protected void dlDiscount_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detailSee")
        {
            AddressBack(e);
        }
        else if (e.CommandName == "buy")
        {

            AddShopCart(e);
        }
    }


    protected void dlHot_ItemCommand(object source, DataListCommandEventArgs e)
    {
        if (e.CommandName == "detailSee")
        {
            AddressBack(e);
        }
        else if (e.CommandName == "buy")
        {

            AddShopCart(e);
        }
    }

    public void AddressBack(DataListCommandEventArgs e)
    {
        Session["address"] = "";
        Session["address"] = "book.aspx";
        Response.Redirect("GoodsInf.aspx?id=" + e.CommandArgument);
    }


    public void AddShopCart(DataListCommandEventArgs e)
    {
        Hashtable hashCar;
        if (Session["ShopCart"] == null)
        {
            hashCar = new Hashtable();
            hashCar.Add(e.CommandArgument, 1);
            Session["ShopCart"] = hashCar;
        }
        else
        {
            hashCar = (Hashtable)Session["ShopCart"];
            if (hashCar.Contains(e.CommandArgument))
            {
                int count = Convert.ToInt32(hashCar[e.CommandArgument].ToString());
                hashCar[e.CommandArgument] = (count + 1);
            }
            else
            {
                hashCar.Add(e.CommandArgument, 1);
            }
        }
    }
    /*public void addshodcart(DataListCommandEventArgs e)
    {
        string name = "12", imageurl ="" , booksyn = "12";
        int  num = 1;
        float hotprice = 52;
        string myconn = ConfigurationManager.AppSettings["ConnectionString"].ToString();
        SqlConnection sqlconn = new SqlConnection(myconn);

        sqlconn.Open();
        //string bookid = "select count(*) from shopping where BookID='" + e.CommandArgument + "'";
        string addshop = "insert into tb_shopping values('" + e.CommandArgument + "','" + name + "','" + hotprice + "','" + num + "','" + booksyn + "','" +  + "')";
        SqlCommand sqlcom = new SqlCommand(addshop, sqlconn);
        sqlcom.ExecuteNonQuery();
        //sqlcom.ExecuteReader();
        sqlconn.Close();
        this.DataBind();

    }*/
    protected void dlDiscount_SelectedIndexChanged(object sender, EventArgs e)
    {

    }
}